package org.example.manager.Impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.example.enums.DomainTypeEnum;
import org.example.manager.DomainManager;
import org.example.mapper.DomainMapper;
import org.example.model.DomainDO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: 谢超
 * @date: 2023/8/23 11:34
 */
@Component
@Slf4j
public class DomainManagerImpl implements DomainManager {

    @Resource
    private DomainMapper domainMapper;

    /**
     * TODO 这里已经基于id去查询，不应该再放上accountNo了，所以后面可以去除accountNo再尝试
     * @param id
     * @param accountNo
     * @return
     */
    @Override
    public DomainDO findById(Long id, Long accountNo) {
        return domainMapper.selectOne(Wrappers.lambdaQuery(DomainDO.class).eq(DomainDO::getId, id).eq(DomainDO::getAccountNo, accountNo));
    }

    @Override
    public DomainDO findByDomainType(Long id, DomainTypeEnum domainTypeEnum) {
        return domainMapper.selectOne(Wrappers.lambdaQuery(DomainDO.class).eq(DomainDO::getId, id).eq(DomainDO::getDomainType, domainTypeEnum));
    }

    @Override
    public int addDomain(DomainDO domainDO) {
        return domainMapper.insert(domainDO);
    }

    @Override
    public List<DomainDO> listOfficalDomain() {
        // 通过枚举直接来作为eq的值
        return domainMapper.selectList(Wrappers.lambdaQuery(DomainDO.class).eq(DomainDO::getDomainType, DomainTypeEnum.OFFICIAL.name()));
    }

    @Override
    public List<DomainDO> listCustomDomain(Long account) {
        // 通过枚举直接来作为eq的值
        return domainMapper.selectList(Wrappers.lambdaQuery(DomainDO.class).eq(DomainDO::getAccountNo,account).eq(DomainDO::getDomainType, DomainTypeEnum.CUSTOM.name()));
    }
}
